package com.model.vo.sys.login;

import com.common.utils.EntityConversionUtil;
import com.core.springSecurity.model.LoginUserDetails;
import com.model.vo.sys.menu.GetSysMenuVO;
import com.model.vo.sys.role.RoleVO;
import com.model.vo.sys.user.LoginVo;
import com.model.vo.sys.user.UserVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Author: zql
 * @Description:
 * @Data: 9:43 2021/7/6
 */

@Builder
public class LoginVO {
    LoginUserDetails loginUserDetails;

    @ApiModelProperty(value = "凭证",required = true)
    String token;


    @ApiModelProperty(value = "部门名字",required = true)
    public String getSysDeptName() {
        return loginUserDetails.getDeptName();
    }

    @ApiModelProperty(value = "登录信息",required = true)
    public LoginVo getLogin(){
        LoginVo loginVo= EntityConversionUtil.copy(loginUserDetails,LoginVo.class);
        loginVo.setLoginTime(new Date(loginUserDetails.getLoginTime()));
        loginVo.setExpireTime(new Date(loginUserDetails.getExpireTime()));
        return loginVo;
    }
    @ApiModelProperty(value = "用户",required = true)
    public UserVO getUser() {
        return  EntityConversionUtil.copy(loginUserDetails.getUser(), UserVO.class);
    }

    public void setToken(String token) {
        this.token = token;
    }
    public String getToken(){
        return token;
    }

    @ApiModelProperty(value = "权限列表",required = true)
    public Set<String> getPermissions(){
        return loginUserDetails.getPermissions();
    }

    @ApiModelProperty(value = "权限标识",required = true)
    public Set<String> getButtons(){
        return loginUserDetails.getButtons();
    }

    @ApiModelProperty(value = "角色列表")
    public List<RoleVO> getRoles(){
      return EntityConversionUtil.copyList(loginUserDetails.getRoles(),RoleVO.class);
    }

    @ApiModelProperty(value = "菜单列表")
    public List<GetSysMenuVO> getMenus(){
        return EntityConversionUtil.copyList(loginUserDetails.getSysMenus(),GetSysMenuVO.class);
    }
}
